import "./style.css"

function ajax(method, url, isAsync, callback) {
  if (window.XMLHttpRequest) {
    var oAjax = new XMLHttpRequest(); //非IE6
  } else {
    var oAjax = new ActiveXObject("Microsoft.XMLHTPP");
  }
  oAjax.open(method, url, isAsync);
  oAjax.send();
  oAjax.onreadystatechange = function () {
    if (oAjax.readyState == 4 && oAjax.status == 200) {
      callback(oAjax.responseText);
    }
  };
}

document.getElementById("btn").addEventListener("click", function () {
    ajax("get", "/api/user", true, function (res) {
      console.log(res); // 数据请求成功后，在控制台输出数据
    });
  });
